const CompressionWebpackPlugin = require('compression-webpack-plugin');
const productionGzipExtensions = ['js', 'css'];
const isProduction = process.env.NODE_ENV === 'production';
module.exports = {
  publicPath: require('./package.json').name,
  outputDir: '../pub/blog-phone',
  devServer: {
    proxy: {
      '/api': {
        target: 'http://www.666ss.club',
        changeOrigin: true,
        pathRewrite: {
          '/api': ''
        }
      },
      '/testApi': {
        target: 'http://localhost:4000/api',
        changeOrigin: true,
        pathRewrite: {
          '/testApi': ''
        }
      }
    }
  },
  configureWebpack: config => {
    if (isProduction) {
      config.plugins.push(new CompressionWebpackPlugin({
        algorithm: 'gzip',
        test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
        threshold: 10240,
        minRatio: 0.8
      }))
    }
  },
  productionSourceMap: false,
  css: {
    loaderOptions: {
      postcss: {
        // 这里的选项会传递给 postcss-loader
        plugins: [
          require('postcss-import'),
          require('autoprefixer'),
          require('postcss-plugin-px2rem')({
            rootValue: 100, // 这里对应的是750的设计图尺寸
            selectorBlackList: ['html', 'node_modeles/*'],
            exclude: /(node_module)/,
            mediaQuery: true,
            propBlackList: ['border-radius', 'border'] // 如果要保持font-size不转换，替换为 ['font-size']
          })
        ]
      }
    }
  }
}